26 Lecture
CS201
Midterm & Final Term Short Notes
Classes and Objects
Classes and objects are the fundamental building blocks of object-oriented programming (OOP). A class is a blueprint or template for creating objects, while an object is an instance of a class. Classes define the attributes and methods that obje
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- What is a class in object-oriented programming? a. An instance of an object b. A function that returns a value c. A blueprint or template for creating objects d. A data type used for arithmetic operations
Answer: c. A blueprint or template for creating objects
- Which of the following is NOT an advantage of using classes and objects? a. Reusability of code b. Encapsulation of data and behavior c. Easier to understand and maintain code d. Slower program execution
Answer: d. Slower program execution
- Which keyword is used to create an object of a class in Python? a. create b. new c. make d. None of the above
Answer: d. None of the above (In Python, objects are created simply by calling the class as if it were a function)
- Which of the following is a characteristic of an object? a. Data b. Behavior c. Both A and B d. None of the above
Answer: c. Both A and B
- Which method is called when an object is created? a. init b. new c. create d. None of the above
Answer: b. new
- Which of the following is a feature of object-oriented programming? a. Inheritance b. Encapsulation c. Polymorphism d. All of the above
Answer: d. All of the above
- What is inheritance in object-oriented programming? a. The process of creating a new object from an existing object b. The ability to create a new class from an existing class c. The process of adding new methods to a class d. The ability to call methods from another class
Answer: b. The ability to create a new class from an existing class
- What is encapsulation in object-oriented programming? a. The ability to hide the internal workings of an object b. The process of creating a new object from an existing object c. The ability to call methods from another class d. The process of adding new methods to a class
Answer: a. The ability to hide the internal workings of an object
- What is polymorphism in object-oriented programming? a. The ability to create a new class from an existing class b. The process of adding new methods to a class c. The ability of objects of different classes to be treated as if they were of the same class d. The ability to call methods from another class
Answer: c. The ability of objects of different classes to be treated as if they were of the same class
- What is the difference between a class and an object? a. A class is a blueprint for creating objects, while an object is an instance of a class. b. A class is an instance of an object, while an object is a blueprint for creating classes. c. A class and an object are the same thing. d. None of the above.
Answer: a. A class is a blueprint for creating objects, while an object is an instance of a class.
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a constructor in a class? Answer: A constructor is a special method in a class that is called when an object of that class is created. It is used to initialize the attributes of the object.
What is inheritance in object-oriented programming? Answer: Inheritance is the process of creating a new class from an existing class. The new class inherits the attributes and methods of the existing class, and can add its own attributes and methods as well.
What is encapsulation in object-oriented programming? Answer: Encapsulation is the practice of hiding the internal workings of an object from the outside world, and exposing only a public interface for interacting with the object.
What is polymorphism in object-oriented programming? Answer: Polymorphism is the ability of objects of different classes to be treated as if they were of the same class. This allows for more flexible and dynamic code.
What is a method in a class? Answer: A method is a function defined within a class, which can access and manipulate the data attributes of an object of that class.
What is an instance variable in a class? Answer: An instance variable is a variable defined within a class, and is specific to each object created from that class.
What is a static variable in a class? Answer: A static variable is a variable defined within a class, but is shared by all objects of that class.
What is the difference between a class and an object? Answer: A class is a blueprint or template for creating objects, while an object is an instance of a class.
What is the difference between a method and a function? Answer: A method is a function defined within a class, and is associated with objects of that class. A function, on the other hand, is not associated with any particular class or object.
What is the relationship between a superclass and a subclass? Answer: A subclass is a new class created from an existing class (the superclass), and inherits the attributes and methods of the superclass. The subclass can add its own attributes and methods as well.